package com.hntech.netty.basic;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @Autho changqi.wu
 * @Date 路在脚下，使劲踩！
 */
public class FileCopy {


    public static void main(String[] args) throws IOException {

        String finFile = "D:\\data.txt" ;

        FileInputStream fin = new FileInputStream(finFile);
        FileChannel finc = fin.getChannel();


        String fout = "D:\\data-out.txt";
        FileOutputStream fos = new FileOutputStream(fout);
        FileChannel fouc = fos.getChannel();

        ByteBuffer buffer = ByteBuffer.allocate(1024);


        while (true){

            buffer.clear();

            int pos = finc.read(buffer);
            if(pos == -1){
                break;
            }

            buffer.flip();

            fouc.write(buffer);
        }

    }



}
